#include "manageraddnewcourse.h"
#include "ui_manageraddnewcourse.h"
#include <QMessageBox>
#include <QDebug>

managerAddNewCourse::managerAddNewCourse(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::managerAddNewCourse)
{
    ui->setupUi(this);
    this->setWindowTitle("添加课程信息");
}

managerAddNewCourse::~managerAddNewCourse()
{
    delete ui;
}


QStringList managerAddNewCourse::getInfo()
{
    return partCourseInfo;
}

void managerAddNewCourse::on_btn_confirm_clicked()
{
    if(this->ui->edit_select_id->text()!=""&&this->ui->edit_course_id->text()!=""&&this->ui->edit_course_name->text()!=""&&this->ui->edit_college->text()!=""&&this->ui->edit_teacher->text()!=""&&this->ui->edit_level->text()!="")
    {
        if(QMessageBox::information(this,"提示",this->ui->edit_course_name->text()+'\n'+this->ui->box_course_time_1->currentText()+this->ui->box_course_time_2->currentText(),"确认")==0)
        {
            setInfo();
            this->close();
        }
    }
    else
    {
        QMessageBox::critical(this,"错误","请输入完整信息！","确认");
    }
}

void managerAddNewCourse::on_btn_exit_clicked()
{
    this->close();
}

void managerAddNewCourse::clearUi()
{
    ui->edit_select_id->clear();
    ui->edit_course_id->clear();
    ui->edit_course_name->clear();
    ui->spin_class->setValue(0);
    ui->spin_credit->setValue(0);
    ui->box_course_charactor->setCurrentIndex(0);
    ui->edit_college->clear();
    ui->edit_teacher->clear();
    ui->edit_level->clear();
    ui->box_course_time_1->setCurrentIndex(0);
    ui->box_course_time_2->setCurrentIndex(0);
    ui->box_course_school->setCurrentIndex(0);
    ui->spin_max_people->setValue(0);
    partCourseInfo.clear();
    partCourseInfo.append("0");
}

void managerAddNewCourse::setInfo()
{
    partCourseInfo.clear();
    partCourseInfo.append(this->ui->edit_select_id->text());
    partCourseInfo.append(this->ui->edit_course_id->text());
    partCourseInfo.append(this->ui->edit_course_name->text());
    QString temp0=QString::number(this->ui->spin_class->value(), 10);
    partCourseInfo.append(temp0);
    QString temp1=QString::number(this->ui->spin_credit->value(), 10);
    partCourseInfo.append(temp1);
    partCourseInfo.append(this->ui->box_course_charactor->currentText());
    partCourseInfo.append(this->ui->edit_college->text());
    partCourseInfo.append(this->ui->edit_teacher->text());
    partCourseInfo.append(this->ui->edit_level->text());
    partCourseInfo.append(this->ui->box_course_time_1->currentText()+this->ui->box_course_time_2->currentText());
    partCourseInfo.append(this->ui->box_course_school->currentText());
    QString temp2=QString::number(this->ui->spin_max_people->value(), 10);
    partCourseInfo.append(temp2);
}
